
# -*- coding: utf-8 -*-
import scrapy
from scrapy import FormRequest, Request
import re


class LoginSpider(scrapy.Spider):
    name = 'login'
    allowed_domains = ['renren.com']
    # start_urls = ['http://renren.com/']
    login_url = 'http://www.renren.com/SysHome.do'

    def start_requests(self):
        yield scrapy.Request(self.login_url, callback=self.login)

    def login(self, response):
        formdata = {
            'email': '13632635022',
            'icode': '',
            'domain': 'renren.com',
            'key_id': '1',
            'captcha_type': 'web_login',
            'password': '3c5dfa573e24ab50aa8634532c6e5999421a17024c57061936c8b7e971d41472',
            'rkey': '39f5c73e6cf678781f380388a097f7fb', }
        yield FormRequest.from_response(response, formdata=formdata, callback=self.parse_login)

    def parse_login(self, response):
        print('>>>>>>>>' + response.text)
        print('=' * 100)
        print("登录成功")
        print(re.findall("<title>(.*?)</title>", response.text))

    def parse(self, response):
        print(response.text)
